package com.score.student.controller;

import com.score.student.domain.dto.ExamAddDTO;
import com.score.student.domain.po.Exam;
import com.score.student.domain.result.Result;
import com.score.student.domain.vo.AllExamVO;
import com.score.student.service.IExamService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author
 * @version 1.0
 */
@Slf4j
@RequestMapping("/exam")
@RestController
@RequiredArgsConstructor
public class ExamController {

    private final IExamService iExamService;


    @PostMapping("/add")
    public Result add(@RequestBody ExamAddDTO examAddDTO){
        log.info("添加成绩管理");
        iExamService.add(examAddDTO);
        return Result.success();
    }

    @GetMapping("/getAll")
    public Result<AllExamVO> allExam(){
        log.info("得到所有考试信息");
        AllExamVO allExamVO = iExamService.allExam();
        return Result.success(allExamVO);
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        log.info("删除id={}的信息",id);
        iExamService.removeById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<Exam> getNameById(@PathVariable Integer id){
        log.info("查询");
        Exam exam = iExamService.queryNameById(id);
        return Result.success(exam);
    }


}
